export default {
  state: {
    // 如果 localStorage 没有存储地址，则使用空数组
    addressList: JSON.parse(localStorage.getItem("addressList")) || []
  },
  mutations: {
    SET_ADDRESS_LIST(state, address) {
      state.addressList.push(address);
      // **这里要使用 state.addressList**
      localStorage.setItem("addressList", JSON.stringify(state.addressList));
    }
  },
  actions: {
    updateAddressList({ commit }, address) {
      commit('SET_ADDRESS_LIST', address); // 提交 mutation 修改地址
    }
  },
  getters: {
    addressList: (state) => state.addressList // 获取地址
  }
}
